home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / Digital Signature Forger / Source / Forger.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-17  |  4.8 KB  |  197 lines  |  [TEXT/KAHL]

  1. /*
  2.  *  Forger
  3.  *  An init for forcing AOCE digital signitures to always succeed or fail.
  4.  *
  5.  *  Copyright © 1993 by David Shayer.  All rights reserved.
  6.  *
  7.  *  File: Forger.c
  8.  */
  9.  
  10.  
  11. /***************************** Includes *******************************/
  12.  
  13. #include <Traps.h>
  14.  
  15. #include "Forger.h"
  16.  
  17.  
  18. /***************************** Routines *******************************/
  19.  
  20. void main (void)
  21. {
  22.     Handle    Self;
  23.     
  24.     asm
  25.     {
  26.         MOVE.L    A0, Self
  27.     }
  28.     Self=RecoverHandle (Self);
  29.     DetachResource (Self);
  30.     
  31.     if (CPUFlag<2)        // we use some 68020 or greater addressing modes
  32.         return;
  33.     InstallPatch ();
  34. }
  35.  
  36.  
  37. void InstallPatch (void)
  38. {
  39.     long    UnimpAddr, DigSigAddr;
  40.     
  41.     DigSigAddr = NGetTrapAddress (_DigitalSignature, ToolTrap);
  42.     
  43.     UnimpAddr = GetTrapAddress (_Unimplemented);
  44.     if (UnimpAddr==DigSigAddr)
  45.         return;
  46.     
  47.     SetAddr (DigSigAddr);
  48.     NSetTrapAddress ((long)DigitalSignaturePatch, _DigitalSignature, ToolTrap);
  49. }
  50.  
  51.  
  52. void SetAddr (long OrigDigSigAddr)
  53. {
  54.     DataRecPtr DataPtr;
  55.     
  56.     DataPtr=GetDataAddr ();
  57.     DataPtr->TrapAddr=OrigDigSigAddr;
  58. }
  59.  
  60.  
  61. DataRecPtr GetDataAddr (void)
  62. {
  63.     DataRecPtr        DataPtr;
  64.  
  65.     asm
  66.     {
  67.         MOVE.L    #kControlAddr, D0
  68.         JSR        DigitalSignaturePatch
  69.         MOVE.L    D0, DataPtr
  70.     }
  71.     return DataPtr;
  72. }
  73.  
  74.  
  75. // do a tail patch!  naughty naughty!
  76. void DigitalSignaturePatch (void)
  77. {
  78.      asm
  79.      {
  80.          ; handle control calls - return addr of storage in D0
  81.          CMP.L        #kControlAddr, D0        ; is it our magic selector?
  82.          BNE.S        @3                        ; if not, skip ahead
  83.          LEA            @DSAddr, A0                ; get addr of our data
  84.          MOVE.L        A0, D0                    ; store addr in return register
  85.          RTS                                    ; return
  86.  
  87.         ; see if forger is on
  88. @3        TST.W        @On                        ; is forger turned on?
  89.         BNE.S        @4                        ; if its on, branch to handler
  90.         MOVE.L        @DSAddr, -(A7)            ; its off, so push addr of _DigitalSignature
  91.         RTS                                    ; jump to _DigitalSignature
  92.  
  93.         ; check for SIGVerify
  94. @4        CMP.L        #kSIGVerify,D0            ; is it SIGVerify?
  95.         BEQ.S        @5                        ; if so, jump to handler
  96.  
  97.         ; check for SIGShowSigner
  98.         CMP.L        #kSIGShowSigner,D0        ; is it SIGShowSigner?
  99.         BEQ.S        @10                        ; if so, jump to handler
  100.  
  101.         ; not a selector we want
  102.         MOVE.L        @DSAddr, -(A7)            ; its not, so push addr of _DigitalSignature
  103.         RTS                                    ; jump to _DigitalSignature
  104.  
  105.         ;;; SIGShowSigner handler ;;;
  106.         ; succeed or fail?
  107. @10        TST.W        @Suceed                    ; test Suceed
  108.         BEQ.S        @12                        ; if its fail, jump ahead
  109.  
  110.         ; handle SIGShowSigner succeed
  111.         ; make real call, let it go if it succeeds, if it fails, force it to succeed
  112.         MOVE.L        A1, -(A7)                ; save A1
  113.         LEA            @Store, A1                ; load addr of storage
  114.         MOVE.L        4(A7), (A1)                ; save real return addr
  115.         LEA            @11, A1                    ; get our return addr
  116.         MOVE.L        A1, 4(A7)                ; insert our return addr
  117.         MOVE.L        (A7)+, A1                ; restore A1
  118.         MOVE.L        @DSAddr, -(A7)            ; push addr of _DigitalSignature
  119.         RTS                                    ; call real _DigitalSignature
  120. @11        TST.W        (A7)                    ; did call succeed?
  121.         BNE.S        @13                        ; if it succeeded, fall thru and return
  122.         MOVE.L        @Store, -(A7)            ; get real return addr
  123.         RTS                                    ; return
  124.  
  125. @13        ; real SIGShowSigner failed, so fake succees
  126.         JSR            FakeSuccees                ; call routine to fake success
  127.         MOVE.W        #0, (A7)                ; set noErr return value
  128.         MOVE.L        @Store, -(A7)            ; get real return addr
  129.         RTS                                    ; return
  130.  
  131.         ; handle SIGVerify fail
  132. @12        ADDQ.L        #8, A7                    ; pop params from stack
  133.         MOVE.W        #kSigSignError, (A7)    ; set error return value
  134.         RTS                                    ; return
  135.         
  136.  
  137.  
  138.  
  139.         ;;; SIGVerify handler ;;;
  140.         ; succeed or fail?
  141. @5        TST.W        @Suceed                    ; test Suceed
  142.         BEQ.S        @7                        ; if its fail, jump ahead
  143.  
  144.         ; handle SIGVerify succeed
  145.         MOVE.L        A1, -(A7)                ; save A1
  146.         LEA            @Store, A1                ; load addr of storage
  147.         MOVE.L        4(A7), (A1)                ; save real return addr
  148.         LEA            @6, A1                    ; get our return addr
  149.         MOVE.L        A1, 4(A7)                ; insert our return addr
  150.         MOVE.L        (A7)+, A1                ; restore A1
  151.         MOVE.L        @DSAddr, -(A7)            ; push addr of _DigitalSignature
  152.         RTS                                    ; call real _DigitalSignature
  153. @6        MOVE.W        #0, (A7)                ; insert an noErr
  154.         MOVE.L        @Store, -(A7)            ; get real return addr
  155.         RTS                                    ; return
  156.         
  157.  
  158.         ; handle SIGVerify fail
  159. @7        MOVE.L        A1, -(A7)                ; save A1
  160.         LEA            @Store, A1                ; load addr of storage
  161.         MOVE.L        4(A7), (A1)                ; save real return addr
  162.         LEA            @8, A1                    ; get our return addr
  163.         MOVE.L        A1, 4(A7)                ; insert our return addr
  164.         MOVE.L        (A7)+, A1                ; restore A1
  165.         MOVE.L        @DSAddr, -(A7)            ; push addr of _DigitalSignature
  166.         RTS                                    ; call real _DigitalSignature
  167. @8        MOVE.W        #kSigVerifyError, (A7)    ; insert an error
  168.         MOVE.L        @Store, -(A7)            ; get real return addr
  169.         RTS                                    ; return
  170.  
  171.         ; data storage
  172. @DSAddr    DC.L        0                        ; addr of _DigitalSignature trap
  173. @On        DC.W        0                        ; 1=forger is on,  0=forger is off
  174. @Suceed DC.W        1                        ; 1=always suceed, 0=always fail
  175. @Store    DC.L        0                        ; temp storage
  176.      }
  177. }
  178.  
  179.  
  180. // do a wimpy immitation of a successful dialog
  181. void FakeSuccees (void)
  182. {
  183.     short    RefNum;
  184.     
  185.     RefNum=OpenResFile ("\pForger Data");
  186.     if (RefNum==-1)
  187.         return;
  188.     Alert (128, NULL);
  189.     CloseResFile (RefNum);
  190. }
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.